package ClassWork.Work_02;

import java.util.Scanner;

public class FingerGuessingGame {
    public static void main(String[] args) {
        System.out.println("猜拳游戏");
        Game();
    }
    public static void Game(){
        int i=3;
        int s=0,f=0,p=0;
        Scanner sc = new Scanner(System.in);
        do {
            System.out.print("请输入账号：");
            String str = sc.nextLine();
            System.out.print("请输入密码：");
            String str2 = sc.nextLine();
            if(str.equals("user") && str2.equals("123")){
                break;
            }else{
                System.out.println("输入的账号或密码错误！");
            }
            i--;
        }while(i>0);
        if(0==i){
            System.exit(2);
        }
        System.out.println("欢迎登录");
        for(int j=1; j<=5; j++){
            System.out.println("1是剪刀，2是石头，3是布");
            System.out.println("请选择：");
            int x = sc.nextInt();
            if(x<1||x>3){
                System.out.println("输入有误！");
                j--;
                continue;
            }
            int y = (int)(Math.random()*3+1);
            switch (x){
                case 1:
                    System.out.println("您出的是剪刀");
                    break;
                case 2:
                    System.out.println("您出的是石头");
                    break;
                case 3:
                    System.out.println("您出的是布");
                    break;
            }
            switch (y){
                case 1:
                    System.out.println("电脑出的是剪刀");
                    break;
                case 2:
                    System.out.println("电脑出的是石头");
                    break;
                case 3:
                    System.out.println("电脑出的是布");
                    break;
            }
            if(x==y){
                System.out.println("平局!");
                p++;
            }else if((x-y)==1||(x==1&&y==3)){
                System.out.println("赢了！");
                s++;
            }else{
                System.out.println("输了");
                f++;
            }
            System.out.println("您还要继续吗？0-退出");
            int t = sc.nextInt();
            if(t==0){
                break;
            }
        }
        System.out.println("游戏结束，总共：" + s + "胜，" + f + "负，" + p + "平");
    }
}
